package com.content.management.domain.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.content.management.domain.dto.SummaryByClassificationDto;
import com.content.management.domain.entity.DictionaryData;
import com.content.management.util.DateHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;

/**
 * @author xinghu
 * @version 1.0
 * @date 2020/4/4 6:00 下午
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "分类管理列表页展示数据", description = "分类管理列表页展示数据")
public class ClassificationVo {

	@ApiModelProperty(value = "主键id")
	private Long id;

	@ApiModelProperty(value = "序号")
	private String dictionaryFlag;

	@ApiModelProperty(value = "分类名称")
	private String classification;

	@ApiModelProperty(value = "排序编号")
	private Integer sortNum;

	@ApiModelProperty(value = "创建时间")
	@JSONField(format = DateHelper.DATE_TIME_FORMAT)
	private LocalDateTime createTime;

	@ApiModelProperty(value = "内容数量")
	private Integer contentNum = 0;

	public static ClassificationVo of(DictionaryData item, Map<String, SummaryByClassificationDto> dtoMap) {
		SummaryByClassificationDto summary = dtoMap.get(item.getDictionaryFlag());
		ClassificationVo vo = new ClassificationVo();
		vo.setDictionaryFlag(item.getDictionaryFlag());
		vo.setClassification(item.getDictionaryData());
		vo.setSortNum(item.getSortNum());
		vo.setCreateTime(item.getCreateTime());
		vo.setId(item.getId());
		if (Objects.nonNull(summary)) {
			vo.setContentNum(summary.getCountNum());
		} else {
			vo.setContentNum(0);
		}
		return vo;
	}
}
